package com.example.demo.server3.handler;

import com.example.demo.server3.affair.ConnectDetection;
import com.example.demo.server3.affair.RealAffair;
import com.example.demo.server3.template.*;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

public class AffairHandler extends ChannelHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ProtocolTemplate protocolTemplate = (ProtocolTemplate) msg;
        if (protocolTemplate instanceof CMPP_CONNECT){
            //接到连接请求,检测身份
            CMPP_CONNECT_RESP cmpp_connect_resp = ConnectDetection.connectDetection(protocolTemplate);
            ctx.channel().writeAndFlush(cmpp_connect_resp.destruct());
        }else if (protocolTemplate instanceof CMPP_SUBMIT){
            CMPP_SUBMIT_RESP cmpp_submit_resp = RealAffair.submit(protocolTemplate);
            ctx.channel().writeAndFlush(cmpp_submit_resp.destruct());
        }

    }
}
